#light

namespace Modelica.Parsers

    open System.IO
    open Lexer       
    open Parser
    open Modelica.Annotations

    /// <summary>
    /// Class encapsulating annotation parsing </summary>
    type AnnotationParser() =
        // Help private member for iterating over GraphicItem list
        static let rec PrintGraphics( graphPrimList )= 
                match graphPrimList with                
                    | primitive :: listRes -> (primitive:GraphicItem).ToString() + System.Environment.NewLine + PrintGraphics(listRes)
                    | [] -> System.String.Empty
        /// <summary>
        /// Member for testing Icon class, takes Icon as a argument an calls ToString() on all its graphic items </summary>
        /// <param name="iconToPrint">
        /// Icon whose graphic content will be described </param>
        /// <returns>
        ///String build from calling ToString() method on list of GraphicItem in Icon</returns>        
        static member CheckIcon (iconToPrint:Modelica.Annotations.Icon) =
            PrintGraphics(List.of_seq(iconToPrint.Graphics))
        /// <summary> 
        ///Parses the annotation given in argument string </summary>
        /// <param name="annotationString">
        /// String with annotation to parse </param>
        /// <returns>
        /// Icon object build from parsed annotation </returns>
        static member ParseIconAnnotation( annotationString :string ) =
            // create buffer for lexing
            let lexbuf = Lexing.from_string annotationString            
            // Call the parser 
            try
                Parser.start Lexer.token lexbuf
            with e ->                               
                let pos = lexbuf.EndPos
                raise ( System.Exception("Annotaion parsing error at line " + (pos.Line + 1).ToString() + " column " + (pos.Column+1).ToString() ,e) )
                    